#ifndef _SRC_NET_HTTP_HTTP_CONTEXT_H_
#define _SRC_NET_HTTP_HTTP_CONTEXT_H_

#include "src/base/time_stamp.h"
#include "src/base/utils.h"
#include "src/net/http/http_request.h"

namespace fio66::net {

class Buffer;
class HttpContext {
 public:
  enum class HttpRequestParseState {
    kExpectRequestLine,
    kExpectHeaders,
    kExpectBody,
    kGotAll
  };

  HttpContext() = default;
  ~HttpContext() = default;

  bool ParseRequest(Buffer* buf, Timestamp receive_time);

  bool GotAll() const;

  void Reset();

  const HttpRequest& Request() const;

  HttpRequest& Request();

 private:
  bool ProcessRequestLine(const char* begin, const char* end);

 private:
  HttpRequestParseState state_ = HttpRequestParseState::kExpectRequestLine;
  HttpRequest request_;
};

}  // namespace fio66::net

#endif  // _SRC_NET_HTTP_HTTP_CONTEXT_H_
